package com.itheima.itheima_health.controller.admin.BookingController;

import com.itheima.itheima_health.constant.MessageConstant;
import com.itheima.itheima_health.entity.PageResult;
import com.itheima.itheima_health.entity.QueryPageBean;
import com.itheima.itheima_health.entity.Result;
import com.itheima.itheima_health.pojo.CheckItem;
import com.itheima.itheima_health.service.CheckitemTermService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import static com.itheima.itheima_health.utils.QiniuUtils.upload2Qiniu;

/**
 * 检查项管理相关接口
 */
@RestController
@RequestMapping("/checkitem")
@Slf4j
@Api(tags = "检查项管理相关接口")
public class CheckitemTermController {

    @Autowired
    private CheckitemTermService bookingService;

    /**
     * 新增检查项
     * @param checkItem
     * @return
     */
    @ApiOperation("新增检查项")
    @PostMapping("/add")
    @PreAuthorize("hasAnyAuthority('CHECKITEM_ADD')")
    public Result CheckitemTermAdd(@RequestBody CheckItem checkItem){
        log.info("新增检查项:{}",checkItem);
        bookingService.CheckitemTermAdd(checkItem);
        return new Result(true, MessageConstant.ADD_CHECKITEM_SUCCESS);
    }

    /**
     * 检查项分页查询
     * @param queryPageBean
     * @return
     */
    @ApiOperation("检查项分页查询")
    @PostMapping("/pageQuery")
    @PreAuthorize("hasAnyAuthority('CHECKITEM_QUERY')")
    public PageResult CheckitemTerPageQuery(@RequestBody QueryPageBean queryPageBean){
        log.info("分页查询:{}",queryPageBean);
        PageResult pageResult = bookingService.CheckitemTerPageQuery(queryPageBean);
        return pageResult;
    }

    /**
     * 根据id删除检查项
     * @param id
     * @return
     */
    @ApiOperation("根据id删除检查项")
    @DeleteMapping("/delete/{id}")
    @PreAuthorize("hasAnyAuthority('CHECKITEM_DELETE')")
    public Result CheckitemTerDelete(@PathVariable Long id){
        log.info("删除检查项:{}",id);
        bookingService.CheckitemTermDelete(id);
        return new Result(true,MessageConstant.DELETE_CHECKITEM_SUCCESS);
    }

    /**
     * 根据id回显检查项数据
     * @param id
     * @return
     */
    @ApiOperation("根据id回显检查项数据")
    @GetMapping("/findById/{id}")
    public Result CheckitemTerGetByid(@PathVariable Long id){
        log.info("根据id回显检查项:{}",id);
        CheckItem checkItem = bookingService.CheckitemTergetByid(id);
        return new Result(true,MessageConstant.QUERY_CHECKITEM_SUCCESS,checkItem);
    }

    /**
     * 编辑检查项
     * @param checkItem
     * @return
     */
    @ApiOperation("编辑检查项")
    @PutMapping("/update")
    @PreAuthorize("hasAnyAuthority('CHECKITEM_EDIT')")
    public Result CheckitemTerUpdate(@RequestBody CheckItem checkItem){
        log.info("编辑检查项:{}",checkItem);
        bookingService.CheckitemTerUpdate(checkItem);
        return new Result(true,MessageConstant.EDIT_CHECKITEM_SUCCESS);
    }
}
